import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


export default new Vuex.Store({
  state: {
    list: [],
    id: 1,
  },
  mutations: {
    addItem(state, payload) {
      const id = state.id++;
      const obj = { id, isComplete: false, text: payload };
      state.list.unshift(obj);
      // console.log(state.list);
    },
    del(state, id) {
      const index = state.list.findIndex((e) => e.id === id);
      state.list.splice(index, 1);
    }
  },
  actions: {},
  getters: {
    doing(state) {
      return state.list.filter((e) => !e.isComplete);
    },
    done(state) {
      return state.list.filter((e) => e.isComplete);
    },
  }
})
